import {
    reqChatList, reqChatDetailList, reqSearchContacts, reqGroupList,
    reqSubmitApply, reqContactsAppLyList, reqApplyStatus, reqContactsInfo,
    reqAddGroup, reqUpdateGroup, reqUpdateContacts, reqDeleteAllOpApply
} from "@/api"
// state：仓库存储数据的地方
const state = {
    chatList: [],
    chatDetailList: [],
    groupList: [],
    applyList: [],
    contactsInfo: {}
}
// mutations：修改state的唯一手段，因此第一个参数必须是state，第二个参数为将要修改的数据
const mutations = {
    SAVE_CHATLIST(state, res) {
        state.chatList = res
    },
    SAVE_CHATDETAILLIST(state, res) {
        state.chatDetailList = res
    },
    SAVE_GROUPLIST(state, res) {
        state.groupList = res
    },
    SAVE_APPLYLIST(state, res) {
        state.applyList = res
    },
    SAVE_CONTACTSINFO(state, res) {
        state.contactsInfo = res
    }
}
// action：书写业务逻辑（method方法）
const actions = {
    async getChatList({ commit }) {
        let res = await reqChatList()
        if (res.success) commit("SAVE_CHATLIST", res.data)
        return res
    },
    async getChatDetailList({ commit }, data) {
        let res = await reqChatDetailList(data)
        if (res.success) commit("SAVE_CHATDETAILLIST", res.data)
        return res
    },
    async searchContacts({ commit }, data) {
        return await reqSearchContacts(data)
    },
    async getGroupList({ commit }) {
        let res = await reqGroupList()
        if (res.success) commit("SAVE_GROUPLIST", res.data)
        return res
    },
    async submitApply({ commit }, data) {
        return await reqSubmitApply(data)
    },
    async getContactsAppLyList({ commit }) {
        let res = await reqContactsAppLyList()
        if (res.success) commit("SAVE_APPLYLIST", res.data)
        return res
    },
    async changeApplyStatus({ commit }, data) {
        return await reqApplyStatus(data)
    },
    async getContactsInfo({ commit }, data) {
        let res = await reqContactsInfo(data)
        if (res.success) commit("SAVE_CONTACTSINFO", res.data)
        return res
    },
    async addGroup({ commit }, data) {
        return await reqAddGroup(data)
    },
    async updateGroup({ commit }, data) {
        return await reqUpdateGroup(data)
    },
    async updateContacts({ commit }, data) {
        return await reqUpdateContacts(data)
    },
    async deleteAllOpApply({commit}){
        return await reqDeleteAllOpApply()
    }
}
// getters：计算属性
const getters = {

}

export default {
    state,
    mutations,
    actions,
    getters
}